//
//  MainTabBarController.m
//  yunyan
//
//  Created by haichuang on 2018/2/11.
//  Copyright © 2018年 haichuang. All rights reserved.
//

#import "MainTabBarController.h"
#import "ServiceViewController.h"
@interface MainTabBarController ()<UITabBarControllerDelegate>
{
    UINavigationController *nav1;
    UINavigationController *nav2;
    UINavigationController *nav3;
    UINavigationController *nav4;
    
}
@end

@implementation MainTabBarController

- (void)viewWillLayoutSubviews{
//    CGRect tabFrame = self.tabBar.frame; //self.TabBar is IBOutlet of your TabBar
//    tabFrame.size.height = 49;
//    tabFrame.origin.y = self.view.frame.size.height - 49;
//    self.tabBar.frame = tabFrame;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.delegate = self;
    
    //初始化4个视图控制器
    UIViewController *vc1 = [[NSClassFromString(@"HomeViewController") alloc]init];
    UIViewController *vc2 = [[NSClassFromString(@"ServiceViewController") alloc]init];
    UIViewController *vc3 = [[NSClassFromString(@"ActivityViewController") alloc]init];
    UIViewController *vc4 = [[NSClassFromString(@"MineViewController") alloc]init];
    
    //为4个视图控制器添加导航栏控制器
    nav1 = [[UINavigationController alloc]initWithRootViewController:vc1];
    nav2 = [[UINavigationController alloc]initWithRootViewController:vc2];
    nav3 = [[UINavigationController alloc]initWithRootViewController:vc3];
    nav4 = [[UINavigationController alloc]initWithRootViewController:vc4];
    
    
    //Tint Color 设置UIImage的渲染模式,UIImageRenderingMode枚举值来设置图片的renderingMode属性 UIImageRenderingModeAlwaysOriginal   // 始终绘制图片原始状态，不使用Tint Color
    vc1.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:[[UIImage imageNamed:@"home_home_default"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"home_home_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
     
    vc2.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"服务" image:[[UIImage imageNamed:@"home_service_default"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"home_service_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    vc3.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"活动" image:[[UIImage imageNamed:@"home_activity_default"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"home_activity_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    vc4.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:[[UIImage imageNamed:@"home_my_default"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"home_my_selected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    //设定Tabbar的点击后的颜色
    [[UITabBar appearance]setTintColor:MAINCOLOR];
    //[[UITabBar appearance]setUnselectedItemTintColor:RGBA(153,153,153,1)];
    
    //设定Tabbar的颜色
    [[UITabBar appearance] setBarTintColor:RGBA(255, 255, 255, 1)];
    self.viewControllers = @[nav1,nav2,nav3,nav4];
    self.selectedIndex = 0;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
